package com.kjc.demo.basic.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.JSON;
import com.kjc.demo.basic.dto.WxAccessTokenDTO;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping(value = "/wx")
@Slf4j
public class WxController {
	
	private static final String appid ="wx6d8e3bb791d870f5";
	private static final String secret = "e533ecda9d0d74f03ec2581c476c09b5";
	private static final String grantType = "client_credential";
	
	@Autowired
	RestTemplate resTemplate;
	
	@GetMapping("/getWxToken")
	public String getMyconfig(HttpServletRequest request) {
		String getAccessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appid+"&secret="+secret;
		WxAccessTokenDTO wxAccessTokenDTO = resTemplate.getForObject(getAccessTokenUrl, WxAccessTokenDTO.class);
		String json = JSONUtil.toJsonStr(wxAccessTokenDTO);
		System.out.println(json);
		return json;
	}
}
